package cn.shiwei.hr;

import cn.shiwei.hr.doc.CourseDoc;
import cn.shiwei.hr.repository.CourseElasticsearchRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@SpringBootTest(classes = SearchApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class EStest {

    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;

    @Autowired
    private CourseElasticsearchRepository courseElasticsearchRepository;

    @Test
    public void test(){
        elasticsearchTemplate.createIndex(CourseDoc.class);
        elasticsearchTemplate.putMapping(CourseDoc.class);
    }

    @Test
    public void test2(){
        CourseDoc doc = new CourseDoc();
        doc.setCourseName("技术的反抗螺丝钉");
        doc.setId(11L);

        courseElasticsearchRepository.save(doc);
    }

    @Test
    public void test3(){
        Iterable<CourseDoc> all = courseElasticsearchRepository.findAll();
        all.forEach(System.out::println);
    }

    @Test
    public void test4(){
        courseElasticsearchRepository.deleteById(1L);
    }
}
